<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>10.类型转换使用技巧</title>
</head>

<body>
  <script>
    // String 转 Number
    /* const string = "99";
    console.log(typeof string);
    console.log(string + 78); //9978 因为string 不是Number
    console.log(string * 1 + 78); //177 因为参与运算而转型了
    console.log(Number(string) + 78); //177 */
    //
    //转String 类型
   /* const number = 66;
    console.log(typeof number); // number
    const str = number + '';
    console.log(typeof str); // string 
    console.log(typeof String(number)); // string */

    const string = "99.9houdunren";
    console.log(parseInt(string)); // 99 后面跟字符串也能转，但是前面不能加字符串，加了会转成NaN
    console.log(parseInt("sdf99sweoir")); // NaN

    console.log(typeof parseInt(string)); //Number 转整型
    console.log( parseFloat(string)); //99.0 转浮点型 会包含小数点
    console.log(typeof parseFloat(string)); //Number
    // 数组 字符串分隔成数组
    console.log("1,2,3".split(",")); //[1,2,3]
    const aar  = [1,2,3];
    console.log(aar.join("|"));
  </script>
</body>

</html>